﻿Array.prototype.contains = function (value) {
	for (i in this) {
		if (this[i] === value) {
			return true;
		}
	}

	return false;
}

String.prototype.contains = function (value) {
	return (this.indexOf(value) !== -1);
}

String.prototype.endsWith = function (value) {
	if (value.length > this.length) {
		return false;
	}

	return (this.lastIndexOf(value) === (this.length - value.length));
}

String.format = function () {
    var format = arguments[0];

    for (var i = 0; i < arguments.length - 1; i++) {
        format = format.replace(new RegExp("\\{" + i + "\\}", "gm"), arguments[i + 1]);
    }

    return format;
}

String.prototype.isDecimal = function () {
	return (this.search(/^[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/) !== -1);
}

String.prototype.startsWith = function (value) {
	if (value.length > this.length) {
		return false;
	}

	return (this.indexOf(value) === 0);
}

String.prototype.trim = function () {
	return this.replace(/^\s+|\s+$/g, '');
}

String.prototype.trimEnd = function () {
	return this.replace(/\s+$/, '');
}

String.prototype.trimStart = function () {
	return this.replace(/^\s+/, '');
}